package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.UpkeepHistory;
import com.sailfish.springbootdemo.service.db1.UpkeepHistoryService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/upkeepHistory")
public class UpkeepHistoryController {

    @Autowired
    private UpkeepHistoryService upkeepHistoryService;

    @PostMapping("/getUpkeepHistoryByAssetNumber")
    public Result getUpkeepHistoryByAssetNumber(String assetNumber, String statusStr, Integer upkeepType, Integer pcbaCompanyId, Integer isCurrent, String searchValue) {
        try {
            return ResultUtil.success(upkeepHistoryService.getUpkeepHistoryByAssetNumber(assetNumber, statusStr, upkeepType, pcbaCompanyId, isCurrent, searchValue));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/updateUpkeepHistory")
    public Result updateUpkeepHistory(UpkeepHistory upkeepHistory) {
        return upkeepHistoryService.updateUpkeepHistory(upkeepHistory);
    }
}
